package com.gxuwz.PangGuangyao.business.action.web;

import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.PangGuangyao.business.entity.Culum;
import com.gxuwz.PangGuangyao.business.entity.CulumStand;
import com.gxuwz.PangGuangyao.business.service.ICulumService;
import com.gxuwz.PangGuangyao.business.service.ICulumStandService;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class CulumAction extends BaseAction implements Preparable,ModelDriven{

	private Culum culum;
	private CulumStand culumStand; 
	private String csId;
	private Result<Culum>pageResult;
	@Autowired
	private ICulumService culumService;
	@Autowired 
	private ICulumStandService culumStandService;
	private  final String LIST_JSP="/WEB-INF/page/web/Culum_list.jsp";
	private  final  String ADD_JSP="/WEB-INF/page/web/Culum_add.jsp";
	@Override
	public Object getModel() {
		
		return culum;
	}
	/**
	 * @return
	 * @author lw
	 * @date 2020.02.20
	 * @description:添加课程
	 */
	public String add(){
		culumStand.setCsId(csId);
		culumStand=culumStandService.findByCsId(culumStand);
		culum.setCulumStand(culumStand);
	  culumService.add(culum);
	return list();
	}
	/**
	 * @return
	 * @author lw
	 * @date 2020.02.25
	 * @description:删除课程
	 */

	public String delete(){
	/*	System.out.println("CId=="+culum.getCId());*/
	culum.setCId(culum.getCId());
	culum=culumService.findByCId(culum);
	culumService.delete(culum);
		return list();
		 
	 }
	/**
	 * @return
	 * @author lw
	 * @date 2020.02.20
	 * @description:分页查询课程列表
	 */

	public String list()
	{
		pageResult=culumService.find(culum, getPage(), getRow());
		forwardView=LIST_JSP;
		return SUCCESS;
		
	}
	/**
	 * @return
	 * @author lw
	 * @date 2020.02.20
	 * @description:打开添加课程页面
	 */

public String openAdd(){
	forwardView=ADD_JSP;
	return SUCCESS;
}
	public void prepare() throws Exception {
		if(null==culum)
		{
			culum=new Culum();
		}
		if(null==culumStand){
			culumStand=new CulumStand();
		}
		
	}

	public Result<Culum> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<Culum> pageResult) {
		this.pageResult = pageResult;
	}
	public String getCsId() {
		return csId;
	}
	public void setCsId(String csId) {
		this.csId = csId;
	}
	
	
	

}
